package cn.b504.qpcr.utils;

import org.docx4j.Docx4J;
import org.docx4j.XmlUtils;
import org.docx4j.dml.wordprocessingDrawing.Anchor;
import org.docx4j.dml.wordprocessingDrawing.Inline;
import org.docx4j.jaxb.Context;
import org.docx4j.model.structure.PageDimensions;
import org.docx4j.model.structure.SectionWrapper;
import org.docx4j.openpackaging.exceptions.Docx4JException;
import org.docx4j.openpackaging.packages.WordprocessingMLPackage;
import org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage;
import org.docx4j.wml.*;
import org.docx4j.wml.PPrBase.Spacing;
import sun.misc.BASE64Decoder;

import javax.xml.bind.JAXBElement;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;

import static org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.createImagePart;

public class Docx4jUtils {
    public static final byte[] LOGO = {-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, -59, 0, 0, 0, 62, 8, 6, 0, 0, 1, -20, 106, -17, -68, 0, 0, 0, 1, 115, 82, 71, 66, 0, -82, -50, 28, -23, 0, 0, 0, 4, 103, 65, 77, 65, 0, 0, -79, -113, 11, -4, 97, 5, 0, 0, 0, 9, 112, 72, 89, 115, 0, 0, 11, 19, 0, 0, 11, 19, 1, 0, -102, -100, 24, 0, 0, 18, 105, 73, 68, 65, 84, 120, 94, -19, 93, -51, -54, 102, 71, 17, -98, 68, -115, -109, -119, 32, 94, -127, -105, -112, 75, 16, 113, -58, -123, -101, 16, 112, -93, 11, -77, 112, 45, 3, 110, 116, 33, 4, 17, -36, -72, -120, -56, -116, -32, 106, 46, 65, 112, 6, 4, -93, 36, 32, -72, 18, 6, 68, 65, 20, 13, -30, 36, -37, -17, 18, -76, -97, -22, 122, -6, 84, -41, -87, -2, 57, -25, 61, -17, 55, -33, 76, -34, 7, -118, -9, -100, -18, -22, -22, -22, -86, -2, -17, 62, -33, 119, -21, -10, -125, 79, -66, 124, -21, -38, 112, -17, -55, 123, -8, 121, -29, -31, -57, -1, -69, -13, -32, -39, -69, 18, 118, 14, 32, 3, 82, -54, 52, -109, 66, -62, 28, 122, 97, 119, 126, -15, -33, 55, -19, 123, 121, -64, -81, 60, 51, 3, -109, -55, 23, 30, 126, -14, 21, 125, -36, -121, 74, -8, -35, -57, -113, -94, 76, -18, 60, -4, -8, 42, -6, 5, -32, 87, -81, -124, 85, -68, 4, -108, 76, -108, 78, -42, 60, 66, -107, -55, -35, -33, -60, 25, -36, 123, -14, -127, 62, -35, -70, -11, -75, 39, 111, -23, -45, 45, 41, 61, -128, -76, -4, -75, -68, 43, -112, -47, -125, -126, 0, -16, -40, 76, 108, -102, -100, -63, -110, 73, 75, -34, -39, 81, 28, 117, 36, -84, -48, 82, 1, -128, 70, 49, -67, 18, 108, -72, -87, -74, 125, -64, -25, 55, 30, 60, -5, 8, -65, 5, 86, 104, -55, -124, 118, 85, -69, -37, -102, 86, 4, 105, -70, 48, 19, -89, -120, -76, 76, 10, -82, 50, 64, 13, -61, -81, -126, -38, 121, 45, 41, 16, -65, -52, -28, 75, -65, -6, -41, 23, -15, 91, -11, -117, 96, -88, 50, -72, -9, -8, 29, -115, -54, 96, -107, -66, -5, -28, -41, -14, -69, 7, 69, 11, 102, -30, 81, 50, -47, 95, 86, -49, -69, 79, 68, -13, 10, 95, 125, 50, -24, -43, -93, 12, 0, -102, 46, -1, -82, -21, 63, 75, -34, 74, -1, -6, -125, -113, -105, 70, -11, -94, -125, 93, -65, -128, 102, 79, 96, 125, 40, -11, 98, 18, 85, -70, 84, 25, 81, -69, 87, -31, 74, 8, 103, -91, 36, -56, 111, 91, 68, -110, 35, 117, 14, -99, -65, 79, 95, -32, 3, 94, 121, -5, -3, -89, -106, -103, 36, 110, -75, 20, 96, -43, -42, 19, 36, -83, 65, 122, -65, 111, -107, -17, 21, -28, -50, 47, -97, -107, -58, -28, -27, 16, -123, 103, 85, -54, -92, -28, -21, 63, -5, -73, 60, 75, -45, -11, 5, -80, -28, 16, 101, 102, -61, -94, 120, -28, -81, -113, 2, -14, -8, 2, 70, 105, 87, 83, 45, 48, -111, 94, -3, -42, -121, -79, -46, 32, 11, -1, -82, -128, 112, -54, -62, -5, -99, -121, -49, 100, -86, 5, 75, 123, 66, 56, -128, 103, 73, -93, 85, 8, -80, -34, -80, -96, -20, 68, -9, 53, 104, -127, -119, -52, 10, -8, 2, 52, -108, -82, 32, 61, 78, -22, 93, -56, -53, -10, -122, -18, -51, -90, -57, -13, -35, -9, -91, -109, 22, -36, 123, 114, 37, -124, 81, -59, -26, 37, 124, -38, 31, 51, -4, -21, -113, -33, 76, -77, -128, -113, -124, 24, -18, 1, -53, 21, 43, 52, 102, 94, 93, -104, -114, 66, -46, -37, 119, -64, 78, 67, -128, -88, -128, -124, -49, -109, -17, -47, -4, -57, 78, 103, -98, 11, -18, 62, 126, -86, 79, 23, -68, 60, -120, -6, 123, 2, 93, 110, 105, -12, 55, 25, 43, 5, -75, 7, -79, -35, 38, -120, -35, -26, 8, -119, -9, -66, 77, -89, 97, -27, -73, 21, 103, 97, -29, 82, 87, 44, -29, -102, 68, 36, -32, -39, 80, 110, 87, -27, -127, -48, -34, -64, 49, 11, 73, 28, 41, 0, 38, -33, -62, 103, 80, -46, 26, -120, -121, 57, 127, 118, 113, 0, -61, 34, 89, -6, 40, -64, 84, 74, -58, -98, 85, -58, 73, 65, -68, 123, -86, 10, 64, 114, 16, -66, 0, 62, -36, -66, 71, 105, 24, -26, -8, -22, 110, 90, 81, 120, 44, 51, 70, -17, -37, 63, -2, 123, 85, -128, -49, 125, -17, -49, -121, 21, 2, 30, -32, -54, 4, -120, -46, 48, -84, 74, -41, -112, 93, 0, 6, -46, -99, -97, -1, 71, 20, -28, -69, 48, 120, -27, 73, 14, -123, -33, -63, -122, 123, -98, 40, 13, -61, 108, 28, -106, 20, 126, 126, 5, -108, 65, 26, -52, -106, -96, -32, 103, -65, -5, -89, 44, -64, 43, -114, -111, -109, -93, -70, -99, 70, 40, 108, -58, 64, -111, -87, -49, 18, 104, 80, -42, -96, 10, 60, -45, 83, -98, 31, -17, 118, 73, 97, 121, -27, -59, -110, 83, -70, -112, 76, 20, 9, -52, 103, -94, -87, 64, 66, -110, -63, 41, -66, 76, -40, 100, -14, -89, -115, -80, 34, 85, -88, -43, -107, -125, 71, 31, 11, 96, -7, -120, 87, 92, -59, 8, -119, 12, 10, 32, -28, -31, -61, -4, -102, 22, 19, -68, -83, -120, -14, -103, -59, -72, 16, 110, 7, 0, -16, -117, 110, 78, -20, 56, 11, 101, -95, 36, 76, 39, -127, 50, 27, 21, -66, -38, -54, -32, -79, -65, 126, -110, 40, -77, 101, -57, 3, -99, 56, -77, 5, -86, 66, 0, 96, -76, 52, 3, 43, 80, -90, -49, -94, -56, -30, -115, 60, -91, -50, -29, 18, 103, -70, 89, -2, 50, -112, -6, -68, 104, 8, -62, 110, 42, 68, 122, -107, 2, 0, 100, 2, 13, -73, 57, 20, 118, 102, 10, 37, -95, -128, 45, -104, 85, 28, -88, -74, 31, -75, -109, -120, 20, -117, 64, -66, -18, 108, 24, -18, 102, 33, 102, -63, 42, 64, -59, 105, 69, 27, -106, 101, 102, -53, 83, 54, -45, 1, -53, 111, -50, 63, -24, 1, 5, 89, 14, 104, 123, -69, -69, -111, -120, 6, -112, 11, -98, 19, -94, -61, -119, -83, -64, 120, 5, -89, -98, -27, -68, -30, -45, -122, -86, -125, -11, -16, -67, -75, -126, 51, -97, -120, -108, -27, 112, -56, 84, -112, 19, 23, -41, -94, -95, -113, -83, 12, 120, 30, 17, -73, -28, -20, 115, 11, 94, -66, -81, -60, -104, 20, -119, 94, -115, 29, 52, -24, 75, -35, -109, -115, -42, -69, 104, 4, 12, -104, -104, -38, 29, -81, 59, 101, -80, -122, 111, -111, -78, 46, 29, 63, 105, 118, 4, 85, 36, 89, -113, 40, -45, 23, 20, 107, -25, 18, -105, 11, 57, -84, 8, -28, -29, 44, 20, -112, -9, 65, 119, -19, -27, -125, 31, -17, -40, -54, -60, -81, 93, 44, 17, 18, -81, 60, 26, 84, 64, 121, 32, 13, -54, -96, -32, -90, 66, 48, 98, 26, 69, -83, -128, 17, 85, 14, -16, 52, -71, -117, 87, 100, 13, -48, -102, -42, 123, -76, 120, 16, 118, -126, 51, -106, 41, -106, -127, -56, 76, 105, -12, -75, 9, 47, 87, 32, -126, 33, 32, 106, 102, 106, 68, -14, -12, -24, -42, 55, 126, -69, 54, 126, 68, 3, -96, 11, -128, -68, -39, -125, 47, -74, 18, 125, 93, -95, -24, 23, 0, -31, 123, -99, 97, -69, 42, -126, 121, 109, -95, -54, 113, 46, -94, 116, 89, 120, 126, -19, -5, 79, -117, 17, 45, 31, 73, 20, -62, -4, -45, 26, 123, 68, 19, 91, -52, 42, 63, -36, -68, -15, 72, 124, -78, 72, -42, -41, 2, -114, 109, 85, 97, 29, 102, -14, -15, -14, -23, 12, 125, -83, -32, 29, -73, 25, -74, -1, -115, -56, 26, -110, 97, -91, 54, 97, 1, 97, -30, -89, 105, 0, 22, -72, 103, 72, 32, -15, -108, 3, 73, 13, 18, -92, 119, 25, 111, -94, -38, 107, 17, -91, -75, 40, -35, -96, -23, -110, 122, -50, 0, 70, 50, -119, 38, 31, 35, 34, 90, 25, 114, -38, 1, 110, -29, -63, -74, -96, -69, -113, -37, -77, 10, 3, 24, 33, -46, -119, -124, -103, -115, -81, -115, 104, -47, -98, -49, -109, 117, 82, 122, 47, 19, -123, -120, 86, -109, -121, -127, 51, 0, -24, -27, -27, 120, -78, 19, -119, 10, 41, 50, 60, -14, 6, 125, -2, 71, 127, 115, 70, -98, -96, 30, -24, -52, 83, -48, 90, -102, -65, 44, -120, 28, 65, 90, 25, -69, 71, 51, -32, -2, 72, 4, 110, 8, -35, 4, -52, -106, -25, 104, -96, 57, 70, -114, 0, -107, 13, -92, 17, 109, 65, 107, -35, -63, 125, 77, -21, 16, 116, 107, -36, -120, -78, -50, -62, 100, -64, 30, -90, 87, 124, -23, -103, -35, 33, -7, -67, -114, 72, 11, 61, -80, -98, -62, 54, -90, -124, -103, 124, 45, 63, 120, -20, -70, 43, -17, -68, 47, 107, 52, -47, -39, -24, -126, 119, 27, -97, 109, -24, 54, -26, 58, 45, 60, 25, -66, 58, 96, 76, -76, -52, 124, -78, -16, 54, 29, -123, 86, -53, 96, -72, -1, -11, -88, -100, -107, -116, 7, -35, -84, -29, -87, -85, 92, -5, 48, -29, 26, 28, -117, 56, 107, 32, 91, 46, 60, 71, -60, -68, -16, 108, 17, 29, -111, -112, 39, 59, 18, -23, -89, 14, 126, 99, 80, 1, 75, 19, 83, -43, 77, -128, 49, 69, 110, -6, 37, 96, 76, -124, 1, -42, -40, -88, 121, -106, -113, -109, 4, 62, 19, 12, 35, -78, -34, 75, 45, 102, -85, 0, 44, -81, 125, -106, -79, -50, 77, 74, 90, -68, 64, -49, 25, -44, -51, -74, -34, 93, -128, 1, 32, 52, -54, -20, 69, -63, -47, 21, -24, -126, -105, 4, -47, -26, -42, 5, -49, 1, 105, 80, -98, -38, 102, -72, -32, -52, -64, 12, 73, 31, 119, -93, 117, -51, -28, -126, 13, 104, 109, -7, -50, 32, -38, -65, -46, -88, 11, -74, 2, -121, 28, -35, -53, -116, -115, -23, 85, 103, -97, -25, 44, 93, 29, -113, 113, -79, -33, 4, -14, -37, -24, -40, 83, -30, -98, 14, 120, -15, 62, 34, -90, -29, 115, 15, -32, -79, 123, 70, 62, 29, -54, 13, 91, 70, 99, 46, -8, -78, -99, -95, -5, -77, -9, -62, -67, 39, -82, -84, -11, 117, 13, 63, 63, 78, 24, 109, -74, 41, -37, 97, -24, -27, -57, 66, -55, -77, -18, -30, 74, -63, 29, 95, 64, 82, -63, -8, -114, -25, 30, -64, 67, -7, 0, -45, 33, 127, 62, -125, 52, 90, -32, -81, -101, 121, -86, 28, -62, -35, 67, 125, 93, -61, 57, 2, -98, -11, 2, 61, -107, -38, -70, -84, 34, 73, -53, -46, 127, 18, 69, 110, -22, 66, -19, 89, 52, 10, 65, 7, -79, -64, -42, 80, 45, 80, -98, -66, -98, -20, 8, 9, -41, -15, -47, -74, 6, -69, 117, 100, 91, 14, 96, 29, 84, -75, 108, 9, 12, -50, 97, 5, 88, -76, -103, 111, 4, 41, -96, 71, 48, 80, -22, -46, -22, -113, 53, 10, -71, -43, 105, 7, 69, 94, 116, -70, -88, 72, -15, -53, 25, -8, -64, 17, 116, -100, 53, 24, -45, -22, 107, 19, 94, 62, -45, 69, 121, 66, -66, -58, 117, 43, 30, -11, -47, -41, -127, 50, -40, 78, -48, -102, 76, -66, 17, -55, -67, -37, -48, 9, 74, 19, 48, 78, 31, -82, -128, 89, -96, -56, 40, 68, -23, 66, 92, -123, -45, 60, 118, 59, 66, 95, 43, -84, 12, -36, 65, 37, -105, 66, -61, -102, -89, 123, 63, -28, 25, -47, 107, 63, -8, 75, 108, 124, 75, -67, -35, 71, 5, -70, 34, -56, -45, -41, 46, 76, 13, 108, 58, -126, -6, -23, 107, 65, 43, -36, -61, -53, -17, -91, -109, -72, -55, -39, 104, 85, 78, 10, 109, 9, -122, -15, 112, -74, 109, -7, 34, -30, 117, -6, 33, -71, -21, 60, 17, 40, 83, 95, -121, -112, -4, 27, -114, 64, 43, 64, -68, -17, -85, -127, -39, 124, -68, -4, 94, 58, -58, 109, 33, 38, 52, -3, 108, 61, -107, 21, -27, -43, -128, -28, 105, 81, 101, -20, 17, 13, 80, 100, 78, 2, -68, -111, 35, 70, -3, -11, 108, 62, 94, 126, 47, -99, -16, -18, 89, -32, -6, 65, -104, -45, 42, -10, -85, 52, 30, 63, -60, -83, -120, 77, 112, -21, 5, -125, 1, 40, 95, 95, -121, 0, 111, -28, -120, -111, -100, -39, 46, 80, -27, -108, 53, 82, 79, -82, -58, -19, -37, -35, -91, -32, -120, -84, 1, -85, 56, 58, 65, 14, 90, -116, -111, 103, -56, -98, 35, 4, 72, -14, -27, -96, -86, 55, 99, 34, 120, -56, -17, 29, -63, 41, 100, -81, 118, 114, 119, 64, 95, 67, 112, -118, 111, 117, -63, 123, 43, 93, 47, -50, 35, -15, -43, 14, 99, -30, -120, -20, -41, -36, -10, -69, 48, 73, -56, -61, -104, -83, 116, -48, 56, -63, -82, 7, -28, 29, 49, -109, -34, -36, -62, 104, -42, 96, 116, 107, 94, 78, 79, 118, -87, 0, 65, 11, -75, 72, 60, 28, 18, -106, -35, 11, 13, 8, -55, 127, -124, -121, -80, 50, -16, -103, -16, 38, 97, 29, 2, -14, -31, 3, -108, 41, -89, -51, -49, -64, 20, 120, 53, 125, 101, -105, 99, -41, 12, 45, 48, -113, -56, 112, 41, 60, -33, 120, 97, -21, 87, 48, -115, -66, -82, 64, -99, -112, 94, -125, 42, 32, 47, -60, -125, 79, -125, 50, 24, 17, 81, 99, 54, 84, 95, 70, 110, -111, 7, -49, -121, -93, -72, 0, -42, 25, 13, -110, -126, -30, -103, -122, -100, -71, 107, 4, 2, 47, 17, -59, 91, 82, -74, -126, 86, -72, 69, -118, 111, 94, 91, 82, 90, 59, 105, -76, 47, 82, 25, 119, -110, 104, -104, 21, 120, -44, -70, 1, -63, 78, -17, 83, 91, -37, -111, 23, 103, 124, -7, 121, 76, -110, -48, 32, -55, -84, 46, 80, 36, -98, -85, -42, 24, -43, -110, -31, 33, 93, -89, -37, 22, 66, -70, 110, 75, -75, -52, -98, -84, -127, -89, 40, -83, -56, 125, 115, -82, 32, 60, -29, -123, 93, 19, -125, -63, -2, -123, 70, -28, 0, -46, -12, 109, 112, 82, 66, -44, -81, 23, 72, -41, -42, -39, 119, 82, 25, 77, -116, -30, -113, -62, -13, -72, 32, -127, 38, 19, 57, 1, -44, -4, 106, 62, -92, -55, -115, 61, 123, -91, -59, 3, 114, 110, 2, -98, -121, 35, 70, -125, 92, 109, -20, 14, -51, -94, 119, 13, -109, 114, -20, 66, 49, -70, 44, 6, -28, 41, 52, -81, -8, -44, 124, -53, 86, 124, -98, -99, 68, 91, -15, 48, -74, -56, -48, -11, 16, -11, -94, -68, 76, -117, 67, -38, 58, 101, 30, -58, -13, -54, -114, -18, -41, 9, -43, 119, -88, -78, -50, -47, 71, 62, -111, 3, -124, -48, -33, 83, 88, -105, -26, -73, -71, -109, -94, -19, -53, 85, -108, 103, -57, 17, -68, -77, 32, 120, 6, -72, -114, 25, -15, 1, -32, -127, -31, 124, 75, 36, -113, -107, 73, -8, 22, -31, -13, -126, -79, -105, -68, -14, 76, -110, -56, 71, 1, -17, 85, -7, -107, 60, -46, 58, -118, -23, 120, 97, -50, -126, -85, 84, 79, 18, 105, 107, 93, -117, -114, 66, 75, 22, -61, -105, -33, -85, -54, 48, -124, -27, -13, -15, 86, 54, -116, -64, -127, -33, -122, 19, 85, 75, 72, -58, -117, 38, 9, 75, 94, -21, 113, -49, -53, -92, 60, -17, -96, 8, -34, 9, 101, -86, 21, 45, -54, 44, 29, 57, -109, -127, -68, 8, 12, -9, -65, 30, 12, -121, 19, -16, 108, 13, 42, 93, -112, 26, -52, -90, 71, 13, -51, -68, -53, -58, 103, -107, 78, -30, 98, -54, -15, 117, -21, 1, 24, 71, 88, 30, -82, -87, -94, -118, 68, 96, 14, -115, -7, -81, -66, 46, -80, -103, -41, 20, -18, 110, -18, 6, 100, 70, 96, -72, -1, -11, -16, -31, -20, 38, 8, -60, -93, -30, 68, -35, 2, 12, -60, 126, -69, 118, 68, 30, 75, 90, -40, -22, 8, -128, 21, 101, 51, -20, -54, -40, -46, -47, -56, 114, 107, -25, -42, 6, -54, 121, -26, 11, -54, 109, 62, -10, -61, -8, -75, -5, 91, -39, 49, -50, 89, 106, 100, 123, 57, -72, -86, -63, -127, -47, -78, -100, -52, -77, -59, 17, -44, 11, -16, 60, -45, 64, 66, 75, 71, 118, 73, -124, -56, -43, -126, -109, -20, -20, 2, -17, -60, -46, -91, 68, 124, -53, -72, 102, 1, -39, 126, -29, 113, -111, -79, 56, -42, 27, 55, 59, 126, -55, -85, 30, -120, -25, 29, -111, -113, -96, 85, -50, -122, 9, 78, 5, -23, 99, 85, -120, -11, -20, -117, -124, -34, -44, -7, -126, 107, -60, 77, 115, -60, -82, 35, -67, 11, 46, 120, -103, -127, 70, -47, -38, -19, -67, -32, -126, 79, 37, -80, 97, -115, 37, -100, -66, 94, 112, -63, 5, 0, 54, -106, -4, 13, -77, 105, -20, 94, -107, 100, -56, -27, 42, 119, -90, 104, -88, -65, 59, 118, -63, 5, -25, 2, 79, -23, 120, -37, 111, 19, -80, 108, -73, 7, 37, 19, -48, -61, -88, -47, 109, -121, 66, -32, -41, -92, 23, 92, 112, 61, 40, 103, 67, -67, 75, 24, 45, 96, -65, 45, -38, -5, 10, -128, 70, 39, -69, -19, -82, -46, -49, -48, -117, -48, 48, -76, -79, 63, -102, 41, 35, 120, 96, 119, 127, -53, -122, 29, -108, -14, 84, 118, -107, 81, -43, -56, -40, 75, -56, -37, -26, 91, -59, -99, -72, -15, -46, -45, 31, 40, 117, 77, 73, -125, 121, -99, 45, -20, 40, 123, 119, 82, 80, 14, 89, 23, -49, -42, -85, 84, -57, -89, -42, -48, -50, -40, -37, -90, 44, 101, -93, -72, 61, -115, -126, -30, 73, -18, -12, -56, 16, 17, 10, -83, -30, -42, -112, 35, -97, -57, -113, 100, 107, -81, 108, 54, -89, -122, 122, 77, 123, -59, 73, -65, -10, -33, 74, -125, 19, 82, -27, 32, -123, 60, -119, -24, 40, -53, -125, 103, -55, 64, -95, -99, 74, -111, 53, 67, 73, 78, 101, 119, -124, -87, -72, -126, 42, -2, -102, 27, -123, 84, 106, 87, -95, -83, -34, -83, -50, -112, 23, 112, 87, -108, -20, -115, -23, -72, 52, 20, 82, -110, -25, -13, 0, 33, -84, -6, -86, -47, -61, 50, 119, 25, 35, -28, -54, 24, 86, 90, 111, -124, 19, 105, 105, -80, 56, 86, 91, 26, 64, -113, 86, -114, 57, 10, 81, -39, 16, -90, -47, 67, 72, 103, 97, -42, 83, -30, 56, 56, 117, 121, 63, 73, 119, 127, -73, -74, -75, 110, -84, 120, 54, -24, 31, 1, 58, 47, -7, -115, 27, 69, -31, -99, -36, 1, -11, -93, -27, -80, 98, 7, 0, -65, -40, -38, -56, 8, -105, 14, -74, 48, -96, 77, -45, 21, -98, 11, -101, -29, -60, -88, 7, 56, -126, 94, 121, -5, -9, 115, -73, -45, 45, -99, -31, 112, -56, -37, -21, -44, -54, 100, 27, 71, -111, 121, 66, -93, -16, -105, -71, 123, 21, -57, -14, 61, -113, 70, -47, -101, 30, 89, -8, -76, -101, 59, 111, -121, 85, -89, -31, 27, 102, 10, 92, -35, 86, 71, -59, -42, -24, 62, -20, -15, 118, 122, 110, -11, 6, -89, -48, -16, -77, -18, 17, 77, 124, -68, 52, -117, -92, 79, 53, 93, -102, 117, -22, 8, 126, 74, -80, -73, 81, -92, -76, 101, -54, 4, 63, -114, 58, 56, -14, 10, -1, 53, 55, -118, -39, 93, 79, 111, -101, 83, 27, 4, -31, 71, -98, -54, 86, -70, 72, 44, -111, 66, -77, 11, 111, 119, 1, 37, -4, 54, 117, 39, -35, -2, -23, 63, -21, -54, 125, 18, -99, -74, 125, 12, -24, -6, -88, -24, -73, 123, 43, -69, -127, 81, -91, -22, 1, 62, 68, 35, 48, -6, 53, -65, 26, -76, 48, -4, -41, -34, 40, -90, 71, 9, 35, -9, -100, -76, 42, 127, -108, 49, -116, 60, 53, 98, -104, 43, -126, -81, -68, -11, -69, 74, -58, 94, -22, -2, -13, -30, -67, 116, 34, 124, -49, 114, -44, 40, 65, -40, 74, 19, 85, -86, 22, -68, 94, 91, 26, 107, -107, -18, -102, 27, -123, 6, 15, 97, -45, -100, -109, 86, 58, 123, -123, 45, -75, -100, -49, 109, 86, -1, -43, -47, 103, -66, -13, -57, 80, 78, -105, 116, -89, -26, -10, 79, -2, 49, -7, -67, -58, 46, 58, -87, 103, -41, -83, -61, -94, -13, -20, 2, 113, 22, 118, 45, 16, 85, -86, 8, -34, 111, 91, 117, -86, -46, -34, -48, 70, -127, 58, 102, -46, 93, -33, -95, 110, 56, -123, 50, 4, -59, 96, 112, 52, 16, 95, 56, -4, -31, 2, 95, 1, -79, 14, -80, 60, 13, -86, -66, -26, -107, -71, -65, -109, 115, 56, -99, 8, -25, -8, -61, -82, -56, 120, -5, 71, -107, -54, -61, -22, 2, -86, -26, -60, -109, 112, -27, -103, 106, -120, 45, 88, 93, -94, 6, -74, -65, 81, -44, 27, 7, 123, -54, -71, 27, -34, -56, 91, 40, -86, -128, -67, -122, 81, 109, -125, -27, 75, -8, -29, -113, -56, -114, -96, -24, 51, -106, 13, -16, 59, 107, 120, -98, -34, -108, 104, 32, 88, 15, 116, 43, -88, -41, 97, 122, -3, 23, -64, 47, 98, -9, 78, 9, 125, -123, -113, -74, 57, -9, 54, 10, -64, 109, 87, -97, 108, 115, 0, 54, 46, -6, 68, -97, 112, 1, -34, 64, 91, -88, -75, 67, -12, -22, 55, -1, 80, -13, 122, 7, -74, 62, 89, 58, 23, 29, -80, 69, 11, -121, -92, -78, -44, 7, -110, -55, -88, 91, 29, 21, -54, 81, 106, 53, 10, -65, 126, 104, 58, 115, 3, 32, -93, -110, -71, 97, -118, 18, -107, 33, 26, 37, -128, 83, 26, 5, 80, 85, -30, 76, -69, -90, 82, 126, -28, 105, -39, -70, -64, 50, 111, -95, 104, 10, 101, 9, -115, -90, 100, -114, 29, -85, -61, 26, 67, 99, 87, 9, -93, 79, 43, -113, -125, 62, 79, -29, -102, -54, -37, 66, -99, 119, -33, -9, -106, 90, -95, -17, -93, 99, 112, -4, 114, -128, -92, -23, -118, 12, 77, 86, -32, 43, 85, -94, 71, -112, -71, -107, -94, -58, 27, -56, -50, -108, 27, -52, 125, -101, 94, 121, -61, -58, -116, 120, 21, -71, -62, -87, -115, 2, 104, -39, 28, 122, -94, 83, -9, 83, 43, -31, 79, -31, -42, -74, 36, -38, 93, 89, -37, 104, 26, 103, -126, 54, -1, -67, -107, 19, -24, -43, 111, 127, 56, -41, 67, -54, -73, -114, -85, -58, 113, -24, 86, 42, 42, -103, -17, 125, 70, 36, 14, 73, -74, 86, 17, 2, -21, 56, 60, 107, -80, 32, 114, -22, 94, -22, 85, -36, 20, 127, 31, -70, -7, 52, 3, 122, 58, 83, -71, -114, 104, 20, 22, -112, -73, 85, 87, -16, 35, -35, -90, 81, 93, -121, -61, 80, -32, -120, -74, -3, -19, -101, -35, 116, 117, -5, -121, 127, 125, 7, -67, -83, -86, 60, -121, -6, 106, -56, -75, 124, 67, 82, -11, -82, 51, 61, -46, 13, 5, 116, -73, 101, -71, -42, -123, -18, 70, 64, 55, -85, -21, 97, 118, -33, -38, -21, -111, 112, 112, 103, 42, -34, -15, -124, -11, -128, -2, 105, 1, -24, -72, -39, 57, -104, 54, 21, 89, 59, -90, 80, 76, -65, 119, -79, -114, 17, 42, -105, 99, -22, 96, -19, -123, 0, -18, -105, -95, 76, 47, 59, 78, 25, 45, 112, 70, 33, 70, 58, -102, -126, 5, -14, -82, 94, -128, -41, 82, -10, 84, -20, 83, 27, 69, -2, -77, 21, -17, -66, -80, 127, -19, 33, -62, -89, -91, 81, 0, -87, -126, -5, 127, 127, 58, 69, -93, 5, -9, 46, 58, -6, 82, 31, 42, -26, -98, 27, -76, -83, 70, 33, 27, 7, 41, 110, -49, -24, 19, 65, 54, 9, 54, -54, 59, 50, 127, 66, 26, 113, -110, -39, 107, -60, 91, 26, -59, -98, 114, 89, 48, 125, 79, -97, 25, 30, 96, -90, 108, 17, -10, 46, -18, 14, -67, -94, 113, -122, 91, -82, -126, 61, 83, 24, 24, 49, -21, -123, 105, 16, 111, -20, -26, 127, 6, -108, 27, 26, -2, -56, 28, 79, -28, -81, 86, 59, 99, 76, -17, 27, 85, -67, 25, -48, -106, -121, -12, 22, 72, 39, -7, 64, -90, -90, 33, 63, -13, -32, 45, -26, -34, 23, -110, -68, -65, -58, -101, -50, 75, 57, 33, 27, 101, 5, 105, 62, -86, -125, -28, -27, -14, 3, -39, 50, -81, -54, -123, 63, -24, 87, -46, 45, -31, -47, 14, 98, -79, 47, 71, 118, -55, 39, -39, -61, -91, 69, 30, -7, 99, -73, -102, -89, -14, 79, -30, 33, 102, -54, -42, 67, -34, 85, -39, -74, -70, -57, -30, 70, 90, 95, -50, -8, 52, 66, 33, -49, 5, -10, -18, 91, -80, 24, 52, 87, -126, 30, -24, 76, 59, 34, 49, -67, 77, -101, 29, -120, -78, -10, -9, -36, 67, 121, -102, -42, -2, -59, -79, 8, -68, 41, 16, 53, 12, 54, 44, 123, -109, -104, 21, -54, 86, -90, 22, -56, -21, 81, -54, 58, -24, 124, 114, -125, 68, -91, -84, 71, 110, -54, -11, -31, 68, -42, 59, -5, -94, -59, 3, -8, 120, -54, -99, 41, 91, 11, -77, 13, 3, -93, -118, 38, -55, 96, 15, -75, -97, -38, 5, 125, 94, 88, 28, 61, 119, 104, -76, -12, 114, -7, 111, 13, -6, 70, -63, -50, 99, -81, 60, -128, -67, -90, -12, -110, 41, -66, -123, -52, 87, -9, -102, 0, -46, -7, -118, -69, 84, -44, -20, 7, -24, -35, 2, 43, -103, -121, 77, 63, -94, -46, -13, 27, -3, 115, 92, 127, -124, 35, 79, 111, 10, 68, 30, 98, 75, -39, 70, 72, 21, 63, -2, -20, -78, 119, -110, -69, 100, -66, -115, 14, -4, -2, -31, 80, -80, 82, 99, -56, -99, 65, 25, -42, -75, 17, -8, 70, 113, -86, 60, -117, 44, 43, 87, -128, -88, -14, 3, -71, 1, 44, -93, -81, 84, -118, -63, 104, -116, -118, 42, 13, 78, -28, -82, 59, 42, 95, -23, -120, 22, -1, 44, 90, 114, 45, 78, -27, 25, -107, -19, 44, 88, -100, 62, 79, -111, -61, 111, 10, 108, 121, 70, 83, -106, 101, 20, 88, 42, -99, 111, 20, 0, 71, -44, -111, 60, -10, 112, -93, 74, 12, 100, 29, -41, 78, -50, 83, -114, 60, 85, -55, -7, -58, -115, 39, 66, -92, 59, -48, -86, 116, 60, 23, -102, -15, 39, 116, 17, 50, -70, -12, 42, 51, 113, 20, 79, -85, 108, 103, 3, -121, -4, 49, 93, 117, -121, -54, -101, -128, -91, 81, 96, 1, -52, 105, 75, -86, 92, -24, 113, 82, 92, -18, -55, -105, -123, -101, 31, 1, -102, 21, -53, -40, 72, -26, -1, 42, 47, -13, -101, -123, 96, -54, -53, -94, 76, -119, -110, 60, -31, 21, 57, -103, -73, -43, -56, 114, -29, -54, 121, 69, -10, -74, -115, -81, -24, -111, -28, -25, 52, 107, 31, -11, 42, 93, -18, 24, 104, -117, -60, 103, -54, 37, 58, 107, 47, -115, 114, -8, -58, 121, -114, 70, -79, -75, 108, 103, 69, 109, 28, 79, 87, -61, 94, -14, -90, 0, -114, -125, 33, -83, -15, -60, -48, 48, 48, -100, -84, -107, -77, -123, 40, -67, 7, 108, -123, 94, 118, 70, 30, 0, -103, 54, -1, -111, 99, 75, 15, 62, -112, 11, 57, 69, 15, -4, -70, 74, 75, -120, -66, 3, 89, -128, -73, -109, 60, 55, 100, 2, 51, 114, -9, -14, -52, -106, -19, 90, 80, -108, 73, 4, 101, 47, -72, 94, -96, 34, 74, 71, -108, 126, 47, -72, -32, 83, 15, -12, -106, 50, 66, -92, -34, -15, -126, 6, 110, -35, -6, 63, -44, 51, 108, -118, 124, -45, -15, -3, 0, 0, 0, 0, 73, 69, 78, 68, -82, 66, 96, -126};

    private static final ObjectFactory FACTORY = Context.getWmlObjectFactory();
    private static Spacing spacingZero;
    private static Spacing spacingNormal;
    private static Spacing spacing1_5;
    private static PPr pPrLeftNormal;
    private static PPr pPrRightNormal;
    private static PPr pPrCenterNormal;
    private static PPr pPrDefaultNormal;
    private static PPr pPrLeft1_5;
    private static PPr pPrRight1_5;
    private static PPr pPrCenter1_5;
    private static PPr pPrDefault1_5;
    private static TcPr tcPr;
    private static TblPr tblPr;

    public static boolean save(WordprocessingMLPackage wordPackage, OutputStream os) {
        try {
            wordPackage.save(os);
        } catch (Docx4JException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    public static boolean savePdf(WordprocessingMLPackage wordPackage, OutputStream os) {
        try {
            Docx4J.toPDF(wordPackage, os);
        } catch (Docx4JException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * 创建标题行
     * 字号 24（大一），加粗
     * 未指定字体
     *
     * @param text  文本内容
     * @param align 文本对齐方式
     */
    public static P createTitle(String text, String align) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 24 << 1, true, "Arial", "SimSun"));
        p.setPPr(getPPr1_5(align));
        return p;
    }

    /**
     * 创建副标题行
     * 字号 18（大二），加粗
     * 未指定字体
     *
     * @param text  文本内容
     * @param align 文本对齐方式
     */
    public static P createSubTitle(String text, String align) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 18 << 1, true, "Arial", "SimSun"));
        p.setPPr(getPPr1_5(align));
        return p;
    }

    /**
     * 创建一级标题行
     * 字号 16（三号），加粗
     * 英文字体（Microsoft Sans Serif），未指定中文字体
     *
     * @param text 文本内容
     */
    public static P createH1(String text) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 16 << 1, true, "Arial", "SimSun"));
        p.setPPr(getPPr1_5("left"));
        return p;
    }

    /**
     * 创建二级标题行
     * 字号 14（四号），加粗
     * 英文字体（Microsoft Sans Serif），未指定中文字体
     *
     * @param text 文本内容
     */
    public static P createH2(String text) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 14 << 1, true, "Arial", "SimSun"));
        p.setPPr(getPPr1_5("left"));
        return p;
    }

    /**
     * 创建正文行
     * 字号 10.5（五号）
     * 英文字体（宋体），中文字体（宋体）
     *
     * @param text 文本内容
     */
    public static P createText(String text) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 21, false, "Arial", "SimSun"));
        p.setPPr(getPPr1_5("left"));
        return p;
    }

    /**
     * 创建正文行
     * 字号 10.5（五号）
     * 英文字体（宋体），中文字体（宋体）
     *
     * @param text1 行标题，加粗
     * @param text2 行正文
     */
    public static P createText(String text1, String text2) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text1, 21, true, "Arial", "SimSun"));
        p.getContent().add(createText(text2, 21, false, "Arial", "SimSun"));
        p.setPPr(getPPr1_5("left"));
        return p;
    }

    /**
     * 创建表格
     * 表格宽度 100%，根据内容自动分配单元格宽度
     * 文本水平居中，垂直居中
     *
     * @param data     二维数据，以字符串 "\n" 为分隔符换行
     * @param topBold  首行是否加粗
     * @param leftBold 首列是否加粗
     */
    public static Tbl createTable(List<List<String>> data, boolean topBold, boolean leftBold) {
        Tbl table = FACTORY.createTbl();
        for (int i = 0; i < data.size(); i++) {
            if (data.get(i).size() == 0) continue;
            Tr tr = FACTORY.createTr();
            for (int j = 0; j < data.get(i).size(); j++) {
                String str = data.get(i).get(j);
                Tc tc = FACTORY.createTc();
                tc.setTcPr(getTcPr());
                if (i == 0) {
                    if (topBold || (j == 0 && leftBold)) {
                        for (String s : str.split("\n")) {
                            tc.getContent().add(createTableTitleText(s));
                        }
                    } else {
                        for (String s : str.split("\n")) {
                            tc.getContent().add(createTableText(s));
                        }
                    }
                } else {
                    if (j == 0 && leftBold) {
                        for (String s : str.split("\n")) {
                            tc.getContent().add(createTableTitleText(s));
                        }
                    } else {
                        for (String s : str.split("\n")) {
                            tc.getContent().add(createTableText(s));
                        }
                    }
                }
                tr.getContent().add(tc);
            }
            table.getContent().add(tr);
        }
        table.setTblPr(getTblPr());
        return table;
    }

    /**
     * 创建右侧悬挂，四周型图片行
     *
     * @param bytes 图片的字节数组
     */
    public static P createLogo(WordprocessingMLPackage wordMLPackage, byte[] bytes) {
        P p = FACTORY.createP();
        R r = FACTORY.createR();
        Drawing drawing = FACTORY.createDrawing();
        try {
            Anchor anchor = createLogoAnchor(createImagePart(wordMLPackage, bytes));
            drawing.getAnchorOrInline().add(anchor);
        } catch (Exception e) {
            e.printStackTrace();
        }
        r.getContent().add(drawing);
        p.getContent().add(r);

        PPr pPr = FACTORY.createPPr();
        pPr.setSpacing(getSpacingZero());

        Jc jc = FACTORY.createJc();
        jc.setVal(JcEnumeration.RIGHT);
        pPr.setJc(jc);
        p.setPPr(pPr);
        return p;
    }

    /**
     * 创建图片行
     *
     * @param bytes 图片的字节数组
     */
    public static P createImageInLine(WordprocessingMLPackage wordMLPackage, byte[] bytes) {
        return createImageInLine(wordMLPackage, bytes, null, null, null);
    }

    /**
     * 创建图片行
     *
     * @param bytes 图片的字节数组
     * @param align 图片对齐方式
     */
    public static P createImageInLine(WordprocessingMLPackage wordMLPackage, byte[] bytes, String align, String filenameHint, String altText) {
        if (align == null) align = "center";
        if (filenameHint == null) filenameHint = "img";
        if (altText == null) altText = "img";
        // w:p / w:r / w:drawing
        P p = FACTORY.createP();
        R r = FACTORY.createR();
        Drawing drawing = FACTORY.createDrawing();
        try {
            Inline inline = createImagePart(wordMLPackage, bytes).createImageInline(filenameHint, altText, 0, 1, false);
            drawing.getAnchorOrInline().add(inline);
        } catch (Exception e) {
            e.printStackTrace();
        }
        r.getContent().add(drawing);
        p.getContent().add(r);
        p.setPPr(getPPrNormal(align));
        return p;
    }

    // 获取无行距，无段前，无段后的段落（Spacing）设置
    private static Spacing getSpacingZero() {
        if (spacingZero == null) {
            spacingZero = FACTORY.createPPrBaseSpacing();
            spacingZero.setBefore(BigInteger.ZERO); // 段前
            spacingZero.setAfter(BigInteger.ZERO);  // 段后
            spacingZero.setLine(BigInteger.ZERO);   // 单倍行距
        }
        return spacingZero;
    }

    // 获取单倍行距，无段前，无段后的段落（Spacing）设置
    private static Spacing getSpacingNormal() {
        if (spacingNormal == null) {
            spacingNormal = FACTORY.createPPrBaseSpacing();
            spacingNormal.setBefore(BigInteger.ZERO); // 段前
            spacingNormal.setAfter(BigInteger.ZERO);  // 段后
            // 单倍行距
            spacingNormal.setLine(BigInteger.valueOf(240));
            spacingNormal.setLineRule(STLineSpacingRule.AUTO);
        }
        return spacingNormal;
    }

    // 获取 1.5 倍行距，段前 0.5 行，段后 0.5 行的段落（Spacing）设置
    private static Spacing getSpacing1_5() {
        if (spacing1_5 == null) {
            spacing1_5 = FACTORY.createPPrBaseSpacing();
            spacing1_5.setBeforeLines(BigInteger.valueOf(50)); // 段前
            spacing1_5.setAfterLines(BigInteger.valueOf(50));  // 段后
            // 1.5 倍行距
            spacing1_5.setLine(BigInteger.valueOf(360));
            spacing1_5.setLineRule(STLineSpacingRule.AUTO);
        }
        return spacing1_5;
    }

    /**
     * 获取单倍行距，无段前，无段后、指定对齐方式的段落（PPr）设置
     *
     * @param align 对齐方式
     */
    private static PPr getPPrNormal(String align) {
        switch (align) {
            case "left":
                if (pPrLeftNormal == null) {
                    pPrLeftNormal = FACTORY.createPPr();
                    pPrLeftNormal.setSpacing(getSpacingNormal());
                    Jc jc = FACTORY.createJc();
                    jc.setVal(JcEnumeration.LEFT);
                    pPrLeftNormal.setJc(jc);
                }
                return pPrLeftNormal;
            case "right":
                if (pPrRightNormal == null) {
                    pPrRightNormal = FACTORY.createPPr();
                    pPrRightNormal.setSpacing(getSpacingNormal());
                    Jc jc = FACTORY.createJc();
                    jc.setVal(JcEnumeration.RIGHT);
                    pPrRightNormal.setJc(jc);
                }
                return pPrRightNormal;
            case "center":
                if (pPrCenterNormal == null) {
                    pPrCenterNormal = FACTORY.createPPr();
                    pPrCenterNormal.setSpacing(getSpacingNormal());
                    Jc jc = FACTORY.createJc();
                    jc.setVal(JcEnumeration.CENTER);
                    pPrCenterNormal.setJc(jc);
                }
                return pPrCenterNormal;
            default:
                if (pPrDefaultNormal == null) {
                    pPrDefaultNormal = FACTORY.createPPr();
                    pPrDefaultNormal.setSpacing(getSpacingNormal());
                }
                return pPrDefaultNormal;
        }
    }

    /**
     * 获取单倍行距，无段前，无段后、指定对齐方式的段落（PPr）设置
     *
     * @param align 对齐方式
     */
    private static PPr getPPr1_5(String align) {
        switch (align) {
            case "left":
                if (pPrLeft1_5 == null) {
                    pPrLeft1_5 = FACTORY.createPPr();
                    pPrLeft1_5.setSpacing(getSpacing1_5());
                    Jc jc = FACTORY.createJc();
                    jc.setVal(JcEnumeration.LEFT);
                    pPrLeft1_5.setJc(jc);
                }
                return pPrLeft1_5;
            case "right":
                if (pPrRight1_5 == null) {
                    pPrRight1_5 = FACTORY.createPPr();
                    pPrRight1_5.setSpacing(getSpacing1_5());
                    Jc jc = FACTORY.createJc();
                    jc.setVal(JcEnumeration.RIGHT);
                    pPrRight1_5.setJc(jc);
                }
                return pPrRight1_5;
            case "center":
                if (pPrCenter1_5 == null) {
                    pPrCenter1_5 = FACTORY.createPPr();
                    pPrCenter1_5.setSpacing(getSpacing1_5());
                    Jc jc = FACTORY.createJc();
                    jc.setVal(JcEnumeration.CENTER);
                    pPrCenter1_5.setJc(jc);
                }
                return pPrCenter1_5;
            default:
                if (pPrDefault1_5 == null) {
                    pPrDefault1_5 = FACTORY.createPPr();
                    pPrDefault1_5.setSpacing(getSpacing1_5());
                }
                return pPrDefault1_5;
        }
    }

    // 获取文本垂直居中、边框单实线的 table cell 设置
    private static TcPr getTcPr() {
        if (tcPr == null) {
            tcPr = FACTORY.createTcPr();
            TcPrInner.TcBorders tcBorders = FACTORY.createTcPrInnerTcBorders();
            //构造边框样式
            CTBorder border = new CTBorder();
            border.setVal(STBorder.SINGLE);
            tcBorders.setTop(border);
            tcBorders.setLeft(border);
            tcBorders.setRight(border);
            tcBorders.setBottom(border);
            tcPr.setTcBorders(tcBorders);

            CTVerticalJc ctVerticalJc = new CTVerticalJc();
            ctVerticalJc.setVal(STVerticalJc.CENTER);
            tcPr.setVAlign(ctVerticalJc);
        }
        return tcPr;
    }

    // 获取表格宽度 100%，根据内容自动分配单元格宽度的 table 设置
    private static TblPr getTblPr() {
        if (tblPr == null) {
            tblPr = FACTORY.createTblPr();
            TblWidth tblWidth = FACTORY.createTblWidth();
            tblWidth.setType("pct");
            tblWidth.setW(BigInteger.valueOf(5000));
            tblPr.setTblW(tblWidth);
        }
        return tblPr;
    }

    /**
     * 获取 R 包裹的文本块
     *
     * @param textValue 文本内容
     * @param fontSize  字号大小
     * @param isBold    是否加粗
     */
    private static R createText(String textValue, long fontSize, boolean isBold, String enFontFamily, String cnFontFamily) {
        R r = FACTORY.createR();
        RPr rpr = FACTORY.createRPr();
        // 设置字体
        RFonts fonts = FACTORY.createRFonts();
        if (enFontFamily != null) fonts.setAscii(enFontFamily);
        if (cnFontFamily != null) fonts.setEastAsia(cnFontFamily);
        rpr.setRFonts(fonts);
        // 设置字体大小
        HpsMeasure hpsMeasure = FACTORY.createHpsMeasure();
        hpsMeasure.setVal(BigInteger.valueOf(fontSize));
        rpr.setSzCs(hpsMeasure);
        rpr.setSz(hpsMeasure);
        // 设置粗体
        BooleanDefaultTrue bold = FACTORY.createBooleanDefaultTrue();
        bold.setVal(isBold);
        rpr.setB(bold);
        r.setRPr(rpr);

        // 设置显示文本
        Text text = FACTORY.createText();
        if (textValue == null) textValue = "";
        text.setValue(textValue);
        text.setSpace("preserve");
        r.getContent().add(text);
        return r;
    }

    /**
     * 获取表格内标题行
     * 字号 10.5（五号），加粗
     * 英文字体（宋体），中文字体（宋体）
     *
     * @param text 文本内容
     */
    private static P createTableTitleText(String text) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 21, true, "Arial", "SimSun"));
        p.setPPr(getPPrNormal("center"));
        return p;
    }

    /**
     * 获取表格内普通行
     * 字号 10.5（五号）
     * 英文字体（宋体），中文字体（宋体）
     *
     * @param text 文本内容
     */
    private static P createTableText(String text) {
        P p = FACTORY.createP();
        p.getContent().add(createText(text, 21, false, "Arial", "SimSun"));
        p.setPPr(getPPrNormal("center"));
        return p;
    }

    // 通过 base64 字符串获取字节数组
    public static byte[] getPicBytes(String base64) {
        try {
            return new BASE64Decoder().decodeBuffer(base64);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return LOGO;
    }

    /**
     * Create a <wp:anchor> element suitable for this image, which can be
     * linked or embedded in w:p/w:r/w:drawing, specifying height and width.  Note
     * that you'd ordinarily use one of the methods which don't require
     * you to specify height (cy).
     */
    private static Anchor createLogoAnchor(BinaryPartAbstractImage binaryPartAbstractImage) throws Exception {
        WordprocessingMLPackage wmlPackage = ((WordprocessingMLPackage) binaryPartAbstractImage.getPackage());
        List<SectionWrapper> sections = wmlPackage.getDocumentModel().getSections();
        PageDimensions page = sections.get(sections.size() - 1).getPageDimensions();
        BinaryPartAbstractImage.CxCy cxcy = BinaryPartAbstractImage.CxCy.scale(binaryPartAbstractImage.getImageInfo(), page);
        long cx = cxcy.getCx(), cy = cxcy.getCy();

        String ml = "<wp:anchor distT=\"0\" distB=\"0\" distL=\"114300\" distR=\"114300\" simplePos=\"0\" relativeHeight=\"251658240\" behindDoc=\"0\" locked=\"0\" layoutInCell=\"1\" allowOverlap=\"1\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\" xmlns:wp=\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\"><wp:simplePos x=\"0\" y=\"0\"/><wp:positionH relativeFrom=\"column\"><wp:posOffset>${posHOffset}</wp:posOffset></wp:positionH><wp:positionV relativeFrom=\"paragraph\"><wp:posOffset>0</wp:posOffset></wp:positionV><wp:extent cx=\"${cx}\" cy=\"${cy}\"/><wp:effectExtent l=\"0\" t=\"0\" r=\"0\" b=\"0\"/><wp:wrapSquare wrapText=\"bothSides\"/><wp:docPr id=\"0\" name=\"logo\" descr=\"logo\"/><wp:cNvGraphicFramePr><a:graphicFrameLocks xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\" noChangeAspect=\"1\"/></wp:cNvGraphicFramePr><a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"><a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\"><pic:nvPicPr><pic:cNvPr id=\"1\" name=\"${filenameHint}\"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed=\"${rEmbedId}\"></a:blip><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x=\"0\" y=\"0\"/><a:ext cx=\"${cx}\" cy=\"${cy}\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:anchor>";

        HashMap<String, String> mappings = new HashMap<>();
        mappings.put("cx", Long.toString(cx));
        mappings.put("cy", Long.toString(cy));
        mappings.put("rEmbedId", binaryPartAbstractImage.getRelLast().getId());
        mappings.put("posHOffset", Long.toString(602 * 9525 - cx));

        Object o = XmlUtils.unmarshallFromTemplate(ml, mappings);
        return (Anchor) ((JAXBElement) o).getValue();
    }
}
